package cn.glutnn.controller;


import cn.glutnn.entity.BankUser;
import cn.glutnn.entity.Result;
import cn.glutnn.entity.dto.LoginDTO;
import cn.glutnn.entity.dto.PasswordDTO;
import cn.glutnn.service.BankService;
import cn.glutnn.service.BankUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * (BankUser)表控制层
 *
 * @author msh
 * @since 2024-10-27 00:37:52
 */
@RestController
@Tag(name = "用户模块接口")
@RequestMapping("/user")
public class BankUserController {
    /**
     * 服务对象
     */
    @Autowired
    private BankUserService bankUserService;




    @Operation(summary = "用户登录")
    @PostMapping("/login")
    public Result login(@Valid @RequestBody LoginDTO loginDTO) {
        return bankUserService.login(loginDTO);
    }

    //用户登出
    @Operation(summary = "用户登出")
    @GetMapping("/logout")
    public Result logout() {
        return bankUserService.logout();
    }



    //用户登录之后，修改用户密码
    @Operation(summary = "用户登录之后，修改用户密码")
    @PutMapping("/loginUpdatePassword")
    public Result<BankUser> updatePassword(@Valid @RequestBody PasswordDTO passwordDTO) {
        return bankUserService.updatePassword(passwordDTO);
    }

    //用户登录之后，根据用户名展示个人信息

    @Operation(summary = "用户登录之后，根据用户名展示个人信息")
    @GetMapping("/loginSelectByUsername")
    public Result<BankUser> selectByName() {

        return bankUserService.selectByName();
    }

    //用户登录之后，根据用户名修改个人基本信息
    @Operation(summary = "用户登录之后，根据用户名修改个人基本信息")
    @PutMapping("/loginUpdateByUsername")
    public Result<BankUser> updateByName(@RequestBody BankUser bankUser) {
        return bankUserService.updateByUsername(bankUser);
    }

    ////根据用户名查询用户

    @Operation(summary = "根据用户名查询用户")
    @GetMapping("/search/{userName}")
    public Result<BankUser> selectUserByName(@PathVariable("userName") String userName) {
        return bankUserService.selectUserByName(userName);
    }

}

